package com.bplow.deep.base.concurrent.synclock;

import java.io.Serializable;
import java.lang.reflect.Method;

import org.springframework.aop.support.StaticMethodMatcherPointcut;
import org.springframework.util.ObjectUtils;

@SuppressWarnings("serial")
abstract class SyncLockOperationSourcePointcut extends StaticMethodMatcherPointcut implements Serializable{

	@Override
	public boolean matches(Method method, Class<?> targetClass) {
		SyncLockAttributeSource tas = getSyncLockAttributeSource();
		return (tas == null || tas.getSyncLockAttribute(method, targetClass) != null);
	}
	
	@Override
	public boolean equals(Object other) {
		if (this == other) {
			return true;
		}
		if (!(other instanceof SyncLockOperationSourcePointcut)) {
			return false;
		}
		SyncLockOperationSourcePointcut otherPc = (SyncLockOperationSourcePointcut) other;
		return ObjectUtils.nullSafeEquals(getSyncLockAttributeSource(), otherPc.getSyncLockAttributeSource());
	}

	@Override
	public int hashCode() {
		return SyncLockOperationSourcePointcut.class.hashCode();
	}

	@Override
	public String toString() {
		return getClass().getName() + ": " + getSyncLockAttributeSource();
	}
	
	protected abstract SyncLockAttributeSource getSyncLockAttributeSource();

}
